Imports Microsoft.VisualBasic
Imports System
Imports System.Web
Imports System.Web.UI

Namespace Wrox.Web.GlobalEvents

    Public Class ThemeModule
        Implements IHttpModule

        Public Sub Dispose() Implements System.Web.IHttpModule.Dispose

        End Sub


        Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init

            AddHandler context.PreRequestHandlerExecute, New EventHandler(AddressOf app_PreRequestHandlerExecute)

        End Sub

        Private Sub app_PreRequestHandlerExecute(ByVal Sender As Object, ByVal E As EventArgs)

            HttpContext.Current.Trace.Write("ThemeModule", "app_PreRequestHandlerExecute")
            Dim p As Page = TryCast(HttpContext.Current.Handler, Page)

            If p IsNot Nothing Then

                Dim pb As ProfileCommon = DirectCast(HttpContext.Current.Profile, ProfileCommon)
                p.Theme = pb.Theme

            End If

        End Sub

    End Class

End Namespace